package CPUfile::Alpha;

use strict;

use vars qw($DEBUG);

$DEBUG = 0;
#
# Parse the /proc/cpuinfo file and return an one-liner characterizing the CPU
# This sub-module is the parsing code for Alpha architectures.
#
# The information comes from the LInux kernel.
# On 2.4.27, x86 info is from arch/i386/kernel/setup.c, procedure show_cpuinfo
# Also implicated is asm/cpufeature.h, apparently.
#
#

# parsed version of cpufile
use vars qw(%keys);
# Model maps (initialized later)
use vars qw(%AMDmap %Intelmap);
use vars qw(%bogofactor);

sub parse {
    my $arch = shift; # architecture from uname()
    my $kernel = shift;
    my $cpufile = shift; # entire content of /proc/cpuinfo

    # TODO: need to count the processors here....
    
    my $cpu1file = $cpufile;
    $cpu1file =~ s/\n\n.*//; # look only at the first CPU
    my @lines = split("\n", $cpu1file);
    # the one-liner won't work when there's a blank value...
    #%keys = map {split(/\s+:\s*/, $_)} @lines;
    for my $line (@lines) {
	if ($line =~ /\s+:\s+/) {
	    $keys{$`} = $'; #'
	}
    }
    my $cpuname = cpuname($kernel);
    return $cpuname . "/" . cpuspeed($cpuname, $cpufile);

}



sub cpuname {
    if ($keys{"cpu"} && $keys{"cpu model"}) {
	return $keys{"cpu"} . " " . $keys{"cpu model"};
    } else {
	warn "Alpha CPU or model not found\n";
	return "Alpha unknown";
    }
}

sub cpuspeed {
    my $cpuname = shift;
    if ($keys{"cycle frequency [Hz]"}) {
	return int($keys{"cycle frequency [Hz]"})/1000000;
    } else {
	warn "no cycle frequency\n";
	return 0;
    }
}

1;
